<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "label".
 *
 * @property integer $id
 * @property string $name
 * @property string $class
 * @property string $description
 * @property string $ctime
 *
 * @property AudioLabel[] $audioLabels
 * @property Audio[] $audios
 */
class Label extends \yii\db\ActiveRecord {
    /**
     * @inheritdoc
     */
    public static function tableName() {
        return 'label';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['name', 'class', 'description'], 'required'],
            [['description'], 'string'],
            [['ctime'], 'safe'],
            [['name', 'class'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'id' => '标签id',
            'name' => '标签名称',
            'class' => '标签分类',
            'description' => '标签简介',
            'ctime' => 'Ctime',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getAudioLabels() {
        return $this->hasMany(AudioLabel::className(), ['label_id' => 'id'])->inverseOf('label');
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getAudios() {
        return $this->hasMany(Audio::className(), ['id' => 'audio_id'])->viaTable('audio_label', ['label_id' => 'id']);
    }
}
